<style>

.editPanel p label{
    width:130px;
    padding-left:15px;
    margin-right:5px;
    nowrap;
}

.pageFormContent .panel .panelContent{
    padding-right:6px;
}


</style>
<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<form method="post" action="${rc.getContextPath()}/manage/workUnit/saveWorkUnit" class=" pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
    <div class="pageContent">
        <div class="pageFormContent"  >
        <input type="hidden" name="navTabId" value="${navTabId!''}">
        <input type="hidden" name="id"
                value="<#if (workUnit.workUnitCode)??>${workUnit.workUnitCode!''}</#if>">
            <div class="editPanel">
                <p>
                        <label><@label key="workUnitCode.C,colon">作业单元编号：</@label></label> <input class="required  alphanumeric toUp"name="workUnitCode" value="<#if (workUnit.workUnitCode)??>${workUnit.workUnitCode!''}</#if>" size="20"
                            type="text" maxlength="20" warn="<@label key="workUnitCodeExist.M">作业单元编号已经存在</@label>"
                        <#if (workUnit.workUnitCode)??> readonly="readonly"<#else> remote="${rc.getContextPath()}/manage/workUnit/validateWorkUnitCode"</#if> /> 
                </p>        
                <p>
                        
                        <label><@label key="workUnitText.C,colon">作业单元描述：</@label></label> <input  name="workUnitText" value="<#if (workUnit.workUnitText)??>${workUnit.workUnitText!''}</#if>" size="20"
                            type="text" maxlength="60"
                            <#if "read"==pattern>
                                readonly="readonly"
                            </#if>
                        />
                        
                </p>    
                <p>
                        <label><@label key="workCenter.C,colon">工作中心：</@label></label> 
                         <#if "read"==pattern>
                        	<input  readonly="readonly" value="${workUnit.workCenterCode!''}" type="text"/>
                        <#else>
							<select style="width:147px;" name="workCenterCode" class="required">
                            <#if  "add"=pattern ><option value=""></option></#if>
                            <#if workCenters??><#if workCenters?size>0><#list workCenters as workCenter>
                            <option value="${workCenter.workCenterCode!''}"
                                 <#if  "add"!=pattern && workUnit.workCenterCode??&& workUnit.workCenterCode==workCenter.workCenterCode> selected="selected" 
                                 </#if>
                                 <#if "read"==pattern>
                                    disabled="disabled"
                                 </#if>
                                 >${workCenter.workCenterCode!''}-${workCenter.workCenterText!''}</option>
                                
                            </#list></#if></#if>
                        </select> 
						</#if>    
                           
                </p> 
                <p>
                        <label><@label key="calendarCode.C,colon">工作日历：</@label></label>
                        <#if "read"==pattern>
                        	<input  readonly="readonly" value="${workUnit.calendarCode!''}" type="text"/>
                        <#else>
							<select name="calendarCode">    
	                        	<#if (workUnit.calendarCode)??>
	                        		<option value="${workUnit.calendarCode!''}">${workUnit.calendarText!''}</option>
	                        	<#else>
	                        		<option value=""></option>
	                        	</#if>            
	                            <#if calendars??>
	                                <#list calendars as calendar>
	                                    <option value="${calendar.calendarCode!''}">${calendar.calendarCode!''}-${calendar.calendarText!''}</option>
	                                </#list>
	                            </#if>
	                        </select>
						</#if>                        
                </p>
                <p>
					<label><@label key="defaultWarehouse.C,colon">默认线边仓库：</@label></label>
					<#if "read"==pattern>
					   <input readonly="readonly" value="${workUnit.warehouseCode!''}" type="text">					   
					   <#else>
						<select  id="mm_warehouseCode" class="allyselect required valid" ref="storageLocation" postField="warehouseCode"  name="warehouseCode" refUrl="${rc.getContextPath()}/manage/warehouse/warehouseChange"
						  default="${workUnit.warehouseCode!''}">						
						</select>
					   
					</#if>
					
				</p>
				<p>
					<label><@label key="defaultStorageLocation.C,colon">默认线边库位：</@label></label>
					   <#if "read"==pattern>
					   <input readonly="readonly" value="${workUnit.storageLocationCode!''}" type="text">
					   	<#else>			    
						<select selectedValue="${workUnit.storageLocationCode!''}" id="storageLocation" field="storageLocationCode" name="storageLocationCode" label="storageLocationText" 
						 >
						</select>
						</#if>
					</p>                                				
                <p>
                        <label>&nbsp;</label> 
                        <label>
                        <input type="checkbox" name="lockFlag" value="1"
                            <#if "read"==pattern>
                            disabled="disabled"
                            </#if>
                            <#if
                            (workUnit.lockFlag)?? && (workUnit.lockFlag == 1)>
                            checked="true"</#if> />
                        <@label key="lock.C">锁定</@label></label>
                </p>
            </div>        
            <div class="panel">
                <h1><@label key="workUnitType.C">作业单元类型</@label></h1>
                    <div>
                         <#if "read"!=pattern>
                        <div id="workUnitTypeBar" class="pBar">
                            <ul class="toolBar">
                                <input id="workUnitTypeCode"  type="hidden" name="workUnitTypeLookup.workUnitTypeCode" type="text" />
                                <input id="typeText"  type="hidden" name="workUnitTypeLookup.typeText" type="text" />
                                <li><a class="add"   width="750" height="350" href="${rc.getContextPath()}/manage/workUnit/selectWorkUnitType?navTabId=${navTabId!''}"  rel="selectWorkUnitType1" lookupGroup="workUnitTypeLookup" callback="workUnitType_callback" title="<@label key='addWorkUnitType.D'>新增作业单元类型</@label>"><span>
                                <@label key='add.B'>新增</@label></span> </a>
                                </li>
                                <li><a href="javascript:" class="delete" onclick="workUnitTypedel()"><span><@label key="delete.B">删除</@label></span> </a>
                                </li>
                            </ul>
                        </div>
                        </#if>
            
                        <table id="workUnitTable" class="table border canopration" width="98%" <#if "add"==pattern>layoutH="310"<#else>layoutH="380"</#if>>
                            <thead >
                                <tr>
                                    <th width="30"><input type="checkbox" group="ids" class="checkboxCtrl">
                                    </th>
                                    <th width="100"><@label key="workUnitTypeCode.C">作业单元类型编号</@label></th>
                                    <th width="100"><@label key="workUnitTypeText.C">作业单元类型描述</@label></th>
                                </tr>
                            </thead>
                            <tbody id="workUnitTypeBody">
                                <#if workUnitTypes??> <#if (workUnitTypes?size>0)> <#list workUnitTypes as workUnitType>
                                <tr id="workUnitType_${workUnitType.workUnitTypeCode!''}" target="workUnitType_workUnitTypeCode" rel="${workUnitType.workUnitTypeCode!''}">
                                    <td ><input type="checkbox" name="ids" class="checkboxCtrl" value="${workUnitType.workUnitTypeCode!''}">
                                    </td>
                                    <td >${workUnitType.workUnitTypeCode!''}</td>
                                    <td >${workUnitType.typeText!''}</td>
                                </tr>
                                </#list><#else>
                                    <#if "read"==pattern>
                                    <tr>
                                        <td colspan="3" class="noData">======<@label key='noListData.C'>列表无数据</@label>=====</font></td>
                                    </tr>
                                    </#if>
                                </#if></#if>
                            </tbody>
                        </table>
            
                    </div>
            </div> 
                            
        </div>

        <#if workUnit??>
            <#assign createInfo=workUnit>
            <#include "/common/createInfo.html">
        </#if>
        <div class="formBar">
            <ul>
                <li>
                <#if "read"!=pattern>
                <div class="buttonActive" id="save">
                        <div class="buttonContent">
                            <button type="submit" onclick="check()"><@label key="save.B">保存</@label></button>
                        </div>
                    </div>
                </#if>
                    </li>
                <li>
                    <#if "read"==pattern>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="button" class="close">
                                    <@label key="close.B">关闭</@label>
                            </button>
                        </div>
                    </div>
                    <#else>
                    <div class="buttonActiveGrey">
                        <div class="buttonContent">
                            <button type="button" class="close">
                                <@label key="cancel.B">取消</@label>
                            </button>
                        </div>
                    </div>
                    </#if>
                </li>
            </ul>
        </div>
</div>
</form>


    
<script type="text/javascript">

function check(){
    
    if(""===$(".pageFormContent select[name='workCenterCode']").first().attr("value"))
    {
        return false;
    }
    else
    {
        $('#workUnitTypeBody input[name="ids"]').attr("checked", true);
    }

}
function workUnitType_callback() {
    var workUnitTypeCode = $("#workUnitTypeBar #workUnitTypeCode").val();
    var typeText = $("#workUnitTypeBar #typeText").val();
    var idArr = new Array();
    var nameArr = new Array();
    idArr = workUnitTypeCode.split(',');
    nameArr = typeText.split(',');
    console.log("workUnitTypeCode: "+workUnitTypeCode);
    var ht = "";
    for ( var i = 0; i < idArr.length; i++) {
        var id = idArr[i];
        var name = nameArr[i];
        var my_element = $("#workUnitType_" + id);
        if (my_element.length == 0) {
            ht += "<tr id='workUnitType_"+id+"'target='workUnitType_workUnitCode' rel='"+id+"'><td width='100'><input  name='ids' value='"+id+"' type='checkbox'></td><td width='100'>"
                    + id
                    + "</td><td width='100'>"
                    + name
                    + "</td></tr>";
        }

    }
    $("#workUnitTypeBody").append(ht);
    $("#workUnitTable", $.pdialog.getCurrent()).jTable();
    $.jTableTool.initGridColumnWidth($("#workUnitTypeBody").parents('.grid:first'));

}

function workUnitTypedel() {
    var count = 0;
    $('input[name="ids"]:checked').each(function(i, e) {
        count++;
    });
    if (count == 0) {
        alertMsg.warn('<@label key="selectWorkUnitType.M">请勾选作业单元类型！</@label>')
    } else {
        alertMsg.confirm("<@label key="delWorkUnitType.M">确定要删除选中的作业单元类型吗？</@label>", {
            okCall : function() {
                $('input[name="ids"]:checked').each(function(i, e) {
                    $("#workUnitType_" + e.value).remove();
                    $.jTableTool.initGridColumnWidth($("#workUnitTypeBody").parents('.grid:first'));
                });
            }
        });
    }
  
}


function getWarehouse(){
	$.DWZajax({
        url:hostUrl +"/warehouse/selectWarehouse",
        
        callback:function(data){
            if(data && data.length > 0){
            	
                var options = "";  
                for(var i=0; i<data.length; i++){ 
                	if(($("select#mm_warehouseCode", $.pdialog.getCurrent()).attr("default"))==data[i].warehouseCode){
                        options += "<option selected='selected' value="+data[i].warehouseCode+">"+data[i].warehouseText+"</option>";

                	}else{      options += "<option value="+data[i].warehouseCode+">"+data[i].warehouseText+"</option>";
                	} 
                }
                $("select#mm_warehouseCode", $.pdialog.getCurrent()).html(options);
                
            }else{
                $("select#mm_warehouseCode", $.pdialog.getCurrent()).html("");
                              
            }
            $("select#mm_warehouseCode", $.pdialog.getCurrent()).change();
        }
    });
}
$(function(){
	　　getWarehouse();
	}); 
	

 
	
</script>
	